/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helpdesk.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author JK
 */
@Entity
@Table(name = "Complaints")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Complaints.findAll", query = "SELECT c FROM Complaints c"),
    @NamedQuery(name = "Complaints.findById", query = "SELECT c FROM Complaints c WHERE c.id = :id"),
    @NamedQuery(name = "Complaints.findByTitle", query = "SELECT c FROM Complaints c WHERE c.title = :title"),
    @NamedQuery(name = "Complaints.findByDescription", query = "SELECT c FROM Complaints c WHERE c.description = :description"),
    @NamedQuery(name = "Complaints.findByPriority", query = "SELECT c FROM Complaints c WHERE c.priority = :priority"),
    @NamedQuery(name = "Complaints.findByDateCreated", query = "SELECT c FROM Complaints c WHERE c.dateCreated = :dateCreated"),
    @NamedQuery(name = "Complaints.findByLastUpdated", query = "SELECT c FROM Complaints c WHERE c.lastUpdated = :lastUpdated"),
    @NamedQuery(name = "Complaints.findByStatus", query = "SELECT c FROM Complaints c WHERE c.status = :status")})

public class Complaints implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
//    @Basic(optional = false)
//    @NotNull
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "Title")
    private String title;
    @Size(max = 2147483647)
    @Column(name = "Description")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Priority")
    private int priority;
    @Column(name = "DateCreated")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCreated;
    @Column(name = "LastUpdated")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdated;
    @Basic(optional = false)
    @NotNull
    @Column(name = "Status")
    private int status;
    @JoinColumn(name = "DepartmentID", referencedColumnName = "ID")
    @ManyToOne()
    private Departments departmentID;
    @JoinColumn(name = "CategoryID", referencedColumnName = "ID")
    @ManyToOne
    private Categories categoryID;
    @JoinColumn(name = "AssignedTo", referencedColumnName = "ID")
    @ManyToOne
    private Accounts assignedTo;
    @JoinColumn(name = "Reporter", referencedColumnName = "ID")
    @ManyToOne
    private Accounts reporter;
    @OneToMany(mappedBy = "complaintID",orphanRemoval=true)
    private List<Notes> notesList;
    @OneToMany(mappedBy = "complaintID",orphanRemoval=true)
    private List<ComplaintsFiles> complaintsFilesList;
    @OneToMany(mappedBy = "complaintID",orphanRemoval=true)
    private List<ComplaintAssignToAccounts> complaintAssignToAccountsList;
    @Transient
    private String categoryName;
    @Transient
    private String departmentName;
    @Transient
    private String statusName;
    
    public String getCategoryName() {
        return categoryName;
    }

    public String getDepartmentName() {
        return departmentName;
    }
    public String getStatusName(){
        return HelpDeskEnums.ComplaintStatus.StatusName[status];
    }
    public Complaints() {
    }

    public Complaints(Integer id) {
        this.id = id;
    }

    public Complaints(Integer id, String title, int priority, int status) {
        this.id = id;
        this.title = title;
        this.priority = priority;
        this.status = status;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getLastUpdated() {
        return lastUpdated;
    }

    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Departments getDepartmentID() {
        if (departmentID != null) {
            departmentName = departmentID.getName();
        }
        return departmentID;
    }

    public void setDepartmentID(Departments departmentID) {
        this.departmentID = departmentID;
    }

    public Categories getCategoryID() {
        if (categoryID != null) {
            categoryName = categoryID.getName();
        }
        return categoryID;
    }

    public void setCategoryID(Categories categoryID) {
        this.categoryID = categoryID;
    }

    public Accounts getAssignedTo() {
        return assignedTo;
    }

    public void setAssignedTo(Accounts assignedTo) {
        this.assignedTo = assignedTo;
    }

    public Accounts getReporter() {
        return reporter;
    }

    public void setReporter(Accounts reporter) {
        this.reporter = reporter;
    }

    @XmlTransient
    public List<Notes> getNotesList() {
        return notesList;
    }

    public void setNotesList(List<Notes> notesList) {
        this.notesList = notesList;
    }

    @XmlTransient
    public List<ComplaintsFiles> getComplaintsFilesList() {
        return complaintsFilesList;
    }

    public void setComplaintsFilesList(List<ComplaintsFiles> complaintsFilesList) {
        this.complaintsFilesList = complaintsFilesList;
    }

    @XmlTransient
    public List<ComplaintAssignToAccounts> getComplaintAssignToAccountsList() {
        return complaintAssignToAccountsList;
    }

    public void setComplaintAssignToAccountsList(List<ComplaintAssignToAccounts> complaintAssignToAccountsList) {
        this.complaintAssignToAccountsList = complaintAssignToAccountsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Complaints)) {
            return false;
        }
        Complaints other = (Complaints) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.title;
    }
}
